package com.yj.generator.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author DengLin
 * @title 字段类型枚举
 * @date 2024/07/04
 */
public enum FieldTypeEnum {

    OBJECT("object","Object","OTHER","Object"),
    TINYINT("tinyint", "Integer", "INTEGER","number"),
    SMALLINT("smallint", "Integer", "INTEGER","number"),
    MEDIUMINT("mediumint", "Integer", "INTEGER","number"),
    INT("int", "Integer", "INTEGER","number"),
    BIGINT("bigint", "Long", "BIGINT","number"),
    FLOAT("float", "Double", "FLOAT","number"),
    DOUBLE("double", "Double", "DOUBLE","number"),
    DECIMAL("decimal", "BigDecimal", "DECIMAL","number"),
    DATE("date", "Date", "DATE","Date"),
    TIME("time", "Time", "TIME","Date"),
    YEAR("year", "Integer", "OTHER","number"),
    DATETIME("datetime", "Date", "TIMESTAMP","Date"),
    TIMESTAMP("timestamp", "Long", "TIMESTAMP","number"),
    CHAR("char", "String", "VARCHAR","string"),
    VARCHAR("varchar", "String", "VARCHAR","string"),
    TINYTEXT("tinytext", "String", "VARCHAR","string"),
    TEXT("text", "String", "VARCHAR","string"),
    MEDIUMTEXT("mediumtext", "String", "VARCHAR","string"),
    LONGTEXT("longtext", "String", "VARCHAR","string");

    private final String value;

    private final String javaType;

    private final String jdbcType;

    private final String typescriptType;


    FieldTypeEnum(String value, String javaType, String jdbcType, String typescriptType) {
        this.value = value;
        this.javaType = javaType;
        this.jdbcType = jdbcType;
        this.typescriptType = typescriptType;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(FieldTypeEnum::getValue).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static FieldTypeEnum getEnumByValue(String value) {
        if (StringUtils.isBlank(value)) {
            return OBJECT;
        }
        for (FieldTypeEnum mockTypeEnum : FieldTypeEnum.values()) {
            if (mockTypeEnum.value.equals(value)) {
                return mockTypeEnum;
            }
        }
        return OBJECT;
    }

    public String getValue() {
        return value;
    }

    public String getJavaType() {
        return javaType;
    }

    public String getJdbcType() {
        return jdbcType;
    }

    public String getTypescriptType() {
        return typescriptType;
    }

}